/**
 * choose
 */
package com.thinkgem.jeesite.zmis.choose.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.zmis.choose.entity.ZmisChoose;
import com.thinkgem.jeesite.zmis.choose.service.ZmisChooseService;

/**
 * 学生选择指导老师Controller
 * @author ll
 * @version 2017-10-11
 */
@Controller
@RequestMapping(value = "${adminPath}/choose/zmisChoose")
public class ZmisChooseController extends BaseController {

	@Autowired
	private ZmisChooseService zmisChooseService;
	
	@ModelAttribute
	public ZmisChoose get(@RequestParam(required=false) String id) {
		ZmisChoose entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = zmisChooseService.get(id);
		}
		if (entity == null){
			entity = new ZmisChoose();
		}
		return entity;
	}
	
	@RequiresPermissions("choose:zmisChoose:view")
	@RequestMapping(value = {"list", ""})
	public String list(ZmisChoose zmisChoose, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ZmisChoose> page = zmisChooseService.findPage(new Page<ZmisChoose>(request, response), zmisChoose); 
		model.addAttribute("page", page);
		return "zmis/choose/zmisChooseList";
	}

	@RequiresPermissions("choose:zmisChoose:view")
	@RequestMapping(value = "form")
	public String form(ZmisChoose zmisChoose, Model model) {
		model.addAttribute("zmisChoose", zmisChoose);
		return "zmis/choose/zmisChooseForm";
	}

	@RequiresPermissions("choose:zmisChoose:edit")
	@RequestMapping(value = "save")
	public String save(ZmisChoose zmisChoose, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, zmisChoose)){
			return form(zmisChoose, model);
		}
		zmisChooseService.save(zmisChoose);
		addMessage(redirectAttributes, "保存选择成功");
		return "redirect:"+Global.getAdminPath()+"/choose/zmisChoose/?repage";
	}
	
	@RequiresPermissions("choose:zmisChoose:edit")
	@RequestMapping(value = "delete")
	public String delete(ZmisChoose zmisChoose, RedirectAttributes redirectAttributes) {
		zmisChooseService.delete(zmisChoose);
		addMessage(redirectAttributes, "删除选择成功");
		return "redirect:"+Global.getAdminPath()+"/choose/zmisChoose/?repage";
	}

}